
package com.flu.kafka.config;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.util.ServerInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SystemInfoLogger implements CommandLineRunner {
    @Value("${spring.datasource.url:#}")
    private String datasource;
    @Value("${server.port}")
    private String port;
    @Value("${server.servlet.context-path}")
    private String contextPath;

    public void run(String... args) {
        if (!"#".equals(this.datasource)){
            log.info("系统启动完成，当前连接的数据库是: {}", this.datasource);
        }
        log.info("Java版本: {}", System.getProperty("java.version"));
        log.info("操作系统: {}", System.getProperty("os.name"));
        log.info("操作系统版本: {}", System.getProperty("os.version"));
        log.info("操作系统架构: {}", System.getProperty("os.arch"));
        log.info("当前的Tomcat的版本: {}",ServerInfo.getServerInfo());
        //获取server.port 的值
        if (null == port || "80".equals( port)){
            port = StrUtil.EMPTY;
        }
        if (null == contextPath){
            contextPath = StrUtil.EMPTY;
        }
        log.info("文档地址: {}","http://localhost:"+port+contextPath+"/doc.html");
    }
}
